const store = {
	state: {
		/**
		 * 用户个人信息
		 */
		userInfo: {},
	},
	mutations: {
		SET_USERINFO: (state, userInfo) => {
			state.userInfo = userInfo;
		},
		SET_ATTR(state, obj) {
			state.userInfo[obj["key"]] = obj["value"];
		},
	},

	actions: {
		// 设置用户个人信息
		setUserInfo({
			commit
		}) {
			return new Promise((resolve, reject) => {
				userInfo().then((resp) => {
					if (resp.code == 200) {
						console.log("用户个人信息", resp);
						commit("SET_USERINFO", resp.data);
						resolve();
					} else {
						reject();
					}
				});
			});
		},
		setAttr({
			commit
		}, obj) {
			return new Promise((resolve) => {
				commit("SET_ATTR", obj);
				uni.showToast({
					icon: "none",
					title: "修改成功",
				});
				resolve();
			});
		},
	}


}

export default user;
